package com.truesai.entities.production;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import com.truesai.dto.ImageFile;
import com.truesai.entities.common.CodeItem;


/**
 * 产品详细信息<br/>
 * 需求分析：<br/>
 * <strong>唯一性:</strong>按照产品的名称、规格、产地区分产品的唯一性。如果唯一性确定条件增加，再抽象出一个产品类别的父表。并在此表上增加字段关联父表id。<br/>
 * @author XuLian
 */
@Entity
@NamedQueries(
{
        @NamedQuery(name = Production.ALL, query = "Select p from Production p"),
        @NamedQuery(name = Production.BY_NAME, query = "Select p from Production p where p.name = :name"),
        @NamedQuery(name = Production.BY_ID, query = "Select p from Production p where p.id = :id") })
@Table(name = "productions")
public class Production
{

    public static final String ALL = "Production.all";

    public static final String BY_NAME = "Production.byName";

    public static final String BY_ID = "Production.byId";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /***大类*/
    @NotNull
    @ManyToOne
    private CodeItem category;
    
    /***小类*/
    @NotNull
    @ManyToOne
    private CodeItem subCategory;

    /***名称*/
    @Column(nullable = false)
    @NotNull
    @Size(min = 2, max = 15)
    private String name;
    
    /***型号*/
    @Column(nullable = false)
    @NotNull
    @Size(min = 2, max = 50)
    private String modelNumber;
    
    /***规格*/
    @Column(nullable = false)
    @NotNull
    @Size(min = 2, max = 50)
    private String specification;
    
    /***产地*/
    @Column
    @Size(min = 2, max = 50)
    private String productionPlace;
    
    /**产品展示货架*/
    @Column
    @Size(min = 2, max = 50)
    private String showShelf;
    
    /**备注*/
    @Column
    @Size(min = 2, max = 50)
    private String memo;
    
    /**产品展示图片*/
    @Transient
    private List<ImageFile> imageFiles;
    

    public Production() {}
    
    public Production(CodeItem category, CodeItem subCategory,
    		String name, String modelNumber, String specification,
    		String productionPlace, String showShelf, String memo) {
    	this.category = category;
    	this.subCategory = subCategory;
    	this.name = name;
    	this.modelNumber = modelNumber;
    	this.specification = specification;
    	this.productionPlace = productionPlace;
    	this.showShelf = showShelf;
    	this.memo = memo;
    }


    @Override
    public String toString() {
        return name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return name;
    }

    public void setUsername(String username) {
        this.name = username;
    }
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	public CodeItem getCategory() {
		return category;
	}

	public void setCategory(CodeItem category) {
		this.category = category;
	}
	public CodeItem getSubCategory() {
		return subCategory;
	}

	public void setSubCategory(CodeItem subCategory) {
		this.subCategory = subCategory;
	}
	
	public String getModelNumber() {
		return modelNumber;
	}

	public void setModelNumber(String modelNumber) {
		this.modelNumber = modelNumber;
	}
	public String getSpecification() {
		return specification;
	}

	public void setSpecification(String specification) {
		this.specification = specification;
	}
	public String getProductionPlace() {
		return productionPlace;
	}

	public void setProductionPlace(String productionPlace) {
		this.productionPlace = productionPlace;
	}
	public String getShowShelf() {
		return showShelf;
	}

	public void setShowShelf(String showShelf) {
		this.showShelf = showShelf;
	}
	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}
	public List<ImageFile> getImageFiles() {
		return imageFiles;
	}

	public void setImageFiles(List<ImageFile> imageFiles) {
		this.imageFiles = imageFiles;
	}
	
}